#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
ll vis[33][33];
ll mp[33][33];
ll a[33][33];
ll n;
ll dx[] = {0, 0, 1, -1};
ll dy[] = {1, -1, 0, 0};
void dfs(ll x, ll y)
{
    if (x < 0 || x > n + 1 || y < 0 || y > n + 1 || mp[x][y] != 0)
        return;
    vis[x][y] = 3;
    mp[x][y] = 3;
    for (ll i = 0; i < 4; i++)
    {
        ll nx = x + dx[i], ny = y + dy[i];

        dfs(nx, ny);
    }
}
void solve()
{
    cin >> n;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= n; j++)
        {
            cin >> mp[i][j];
        }
    }
    // cout << 1;
    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= n; j++)
        {
            if (mp[i][j] == 1)
            {
                vis[i][j] = 1;
            }
            else
            {
                vis[i][j] = 2;
            }
        }

    dfs(0, 0);
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= n; j++)
        {
           // cout << vis[i][j];
            if (vis[i][j] == 3)
            {
                cout << 0;
            }
            else if (vis[i][j] == 1)
            {
                cout << 1;
            }
            else
            {
                cout << 2;
            }
            cout << " ";
        }
        cout << endl;
    }
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
